package com.premedsidekick;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class MedAppLogInActivity extends Activity {
    /** Called when the activity is first created. */
	private EditText aUsername;
	private EditText aPassword;
	
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        aUsername= (EditText)findViewById(R.id.username);
        aPassword= (EditText)findViewById(R.id.password);
        
        //Handle SUBMIT button
        setSubmitClickListener();
    }
  //Handle SUBMIT button
    private void setSubmitClickListener() {
    	Button submitButton = (Button)findViewById(R.id.submit);
    	submitButton.setOnClickListener(
    			new View.OnClickListener() {
					
					@Override
					public void onClick(View v) {
						saveStateandDiag(); 
						
						}

				}
    	);
    }
    
    private void saveStateandDiag() {
		String username=aUsername.getText().toString();
		String password=aPassword.getText().toString();
		if ((username.length() ==0) || (password.length() == 0))
		{
			Toast.makeText(MedAppLogInActivity.this, getString(R.string.debug_3), Toast.LENGTH_LONG).show();
		}
		if (username.equalsIgnoreCase(password))
		{
			//Toast.makeText(MedAppLogInActivity.this, getString(R.string.debug_1), Toast.LENGTH_LONG).show();
			switchPage();
		}
		else //no matching	
		{
			Toast.makeText(MedAppLogInActivity.this, getString(R.string.debug_2), Toast.LENGTH_LONG).show();
		}
	}
    private void switchPage() {
    	Intent switchToPage = new Intent(this, HomePageActivity.class);
    	startActivity(switchToPage);
    }
    /*@Override
    protected void onStop() {
    	super.onStop(); 
    }*/
}